package com.bdqn.wang.dao.impl;

import com.bdqn.wang.dao.NewsDao;
import com.bdqn.wang.pojo.News;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class NewsDaoImpl extends BaseDao implements NewsDao {
    @Override
    public List<News> getAll() {
        Connection connecton = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        try {
            connecton = getConnection();
            String sql ="select * from easybuy_news";
            preparedStatement =connecton.prepareStatement(sql);
            resultSet = preparedStatement.executeQuery();
            List<News> list = new ArrayList<News>();
                while (resultSet.next()){
                News news = new News();
                news.setId(resultSet.getInt(1));
                news.setTitle(resultSet.getString(2));
                news.setContent(resultSet.getString(3));
                news.setCreateTime(resultSet.getString(4));
                list.add(news);
            }
            return list;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            closeAll(resultSet,preparedStatement,connecton);
        }
        return  null ;
    }
}
